home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Utilities / Programming / Snippets 2.4 / Snippets / Snippets.rsrc / TEXT_404_4.txt < prev    next >
Encoding:
Text File  |  1996-01-21  |  12.8 KB  |  525 lines

  1. /**********************************************************************
  2.  
  3.     SampleDialog.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     A sample case demonstrating a movable model dialog box.  Need 
  9.     System 7 for pop-up menu functionality.
  10. */
  11.  
  12. /********** Includes */
  13. #include <Dialogs.h>
  14. #include "Fn_Prototypes.h"
  15. #include "MainWindow.h"
  16.  
  17.  
  18. /********** Defines */
  19. #define SAMPLE_DLOG    500
  20. #define NIL_PTR        0L
  21. #define ALLOCATE_MEM   0
  22. #define IN_FRONT       (WindowPtr)-1L
  23. #define RETURN_KEY     13
  24. #define ENTER_KEY      3
  25. #define ESCAPE_KEY     27
  26. #define PERIOD_KEY     46
  27. #define VISUAL_DELAY   8  // standard is 8 ticks
  28.  
  29. #define OK_BUTTON      1
  30. #define CANCEL_BUTTON  2
  31. #define NAME           5
  32. #define PHONE          6
  33. #define MALE_RADIO     7
  34. #define FEMALE_RADIO   8
  35. #define MARRIED_BOX    10
  36. #define DB             11
  37.  
  38.  
  39. /********** Prototypes */
  40. Boolean        MySampleDialog( void );
  41. pascal Boolean MyDialogEventFilter( DialogPtr    theDialog,
  42.                                     EventRecord  *theEvent,
  43.                                     short        *itemHit );
  44.  
  45. /********** SampleDialog */
  46.  
  47. Boolean MySampleDialog( void )
  48. {
  49.     WindowPtr   docWindow;
  50.     DialogPtr   dialog;
  51.     Boolean     done;
  52.     Boolean     result;
  53.     short       itemHit;
  54.     short       itemType;
  55.     Handle      itemHandle;
  56.     Rect        itemRect;
  57.     EventRecord theEvent;
  58.     
  59.     Boolean     isMale;
  60.     Boolean     isFemale;
  61.     Boolean     isMarried;
  62.     int         phoneDB;
  63.     Str255      name;
  64.     Str255      phone;
  65.  
  66.     result = FALSE;
  67.  
  68.     docWindow = FrontWindow();
  69.     if( docWindow != NIL_PTR )
  70.         MyDoDeactivateWindow( docWindow );
  71.  
  72.     dialog = GetNewDialog( SAMPLE_DLOG, ALLOCATE_MEM, IN_FRONT );
  73.  
  74.     if( dialog == NIL_PTR )
  75.         return( result );
  76.  
  77.     /* AdjustMenus_(); */
  78.     ShowWindow( dialog );
  79.     FnMisc_FrameButton( dialog, OK_BUTTON );
  80.  
  81.     done = FALSE;
  82.     while( done == FALSE )
  83.     {
  84.         ModalDialog( &MyDialogEventFilter, &itemHit );
  85.  
  86.         switch( itemHit )
  87.         {
  88.             case OK_BUTTON:
  89.                 result = TRUE;
  90.                 done = TRUE;
  91.                 break;
  92.             case CANCEL_BUTTON:
  93.                 done = TRUE;
  94.                 break;
  95.             case MALE_RADIO:
  96.                 GetDItem( dialog,
  97.                           MALE_RADIO,
  98.                           &itemType,
  99.                           &itemHandle,
  100.                           &itemRect );
  101.                 SetCtlValue( (ControlHandle)itemHandle, TRUE );
  102.                 GetDItem( dialog,
  103.                           FEMALE_RADIO,
  104.                           &itemType,
  105.                           &itemHandle,
  106.                           &itemRect );
  107.                 SetCtlValue( (ControlHandle)itemHandle, FALSE );
  108.                 break;
  109.             case FEMALE_RADIO:
  110.                 GetDItem( dialog,
  111.                           FEMALE_RADIO,
  112.                           &itemType,
  113.                           &itemHandle,
  114.                           &itemRect );
  115.                 SetCtlValue( (ControlHandle)itemHandle, TRUE );
  116.                 GetDItem( dialog,
  117.                           MALE_RADIO,
  118.                           &itemType,
  119.                           &itemHandle,
  120.                           &itemRect );
  121.                 SetCtlValue( (ControlHandle)itemHandle, FALSE );
  122.                 break;
  123.             case MARRIED_BOX:
  124.                 GetDItem( dialog,
  125.                           MARRIED_BOX,
  126.                           &itemType,
  127.                           &itemHandle,
  128.                           &itemRect );
  129.                 if( GetCtlValue( (ControlHandle)itemHandle ) )
  130.                     SetCtlValue( (ControlHandle)itemHandle, FALSE );
  131.                 else
  132.                     SetCtlValue( (ControlHandle)itemHandle, TRUE );
  133.                 break;
  134.         }
  135.      }
  136.  
  137.     GetDItem(dialog,MALE_RADIO,&itemType,&itemHandle,&itemRect);
  138.     isMale = GetCtlValue((ControlHandle)itemHandle);
  139.     GetDItem(dialog,FEMALE_RADIO,&itemType,&itemHandle,&itemRect);
  140.     isFemale = GetCtlValue((ControlHandle)itemHandle);
  141.     GetDItem(dialog,MARRIED_BOX,&itemType,&itemHandle,&itemRect);
  142.     isMarried = GetCtlValue((ControlHandle)itemHandle);
  143.  
  144.     GetDItem(dialog,NAME,&itemType,&itemHandle,&itemRect);
  145.     GetIText(itemHandle,name);
  146.     GetDItem(dialog,PHONE,&itemType,&itemHandle,&itemRect);
  147.     GetIText(itemHandle,phone);
  148.  
  149.     GetDItem(dialog,DB,&itemType,&itemHandle,&itemRect);
  150.     phoneDB = GetCtlValue((ControlHandle)itemHandle);
  151.  
  152.     DisposDialog( dialog );
  153.  
  154.     return( result );
  155. }
  156.  
  157.  
  158. /********** PASCAL MyDialogEventFilter */
  159.  
  160. pascal Boolean MyDialogEventFilter( DialogPtr    theDialog,
  161.                                     EventRecord  *theEvent,
  162.                                     short        *itemHit )
  163. {
  164.     short          thePart;
  165.     char           key;
  166.     short          itemType;
  167.     Handle         itemHandle;
  168.     Rect           itemRect;
  169.     long           finalTicks;
  170.     Rect           dragRect;
  171.     Boolean        result;
  172.     WindowPtr      theWindow;
  173.     
  174.     result = FALSE;
  175.     dragRect = qd.screenBits.bounds;
  176.  
  177.         switch( (*theEvent).what )
  178.         {
  179.             case mouseDown:
  180.                 thePart = FindWindow( (*theEvent).where, &theWindow );
  181.                 if( theWindow == theDialog )
  182.                 {
  183.                 switch( thePart )
  184.                     {
  185.                         case inDrag:
  186.                             DragWindow( theDialog,
  187.                                         (*theEvent).where,
  188.                                         &dragRect );
  189.                             result = TRUE;
  190.                             break;
  191.                     }
  192.                 }
  193.                 break;
  194.             case keyDown:
  195.             case autoKey:
  196.                 key = (*theEvent).message & charCodeMask;
  197.                 if( (key == RETURN_KEY) || (key == ENTER_KEY) )
  198.                 {
  199.                     *itemHit = OK_BUTTON;
  200.                     GetDItem( theDialog,
  201.                               OK_BUTTON,
  202.                               &itemType,
  203.                               &itemHandle,
  204.                               &itemRect );
  205.                     HiliteControl( (ControlHandle)itemHandle,
  206.                                    inButton );
  207.                     Delay( VISUAL_DELAY, &finalTicks );
  208.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  209.                     result = TRUE;
  210.                 }
  211.                 if( (key == ESCAPE_KEY) ||
  212.                     (((*theEvent).modifiers & cmdKey) &&
  213.                     (key == PERIOD_KEY)) )
  214.                 {
  215.                     *itemHit = CANCEL_BUTTON;
  216.                     GetDItem( theDialog,
  217.                               CANCEL_BUTTON,
  218.                               &itemType,
  219.                               &itemHandle,
  220.                               &itemRect );
  221.                     HiliteControl( (ControlHandle)itemHandle,
  222.                                    inButton );
  223.                     Delay( VISUAL_DELAY, &finalTicks );
  224.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  225.                     result = TRUE;
  226.                 }
  227.                 /* Handle other keyboard equivalents here */
  228.                 break;
  229.             case updateEvt:
  230.                 if( (WindowPtr)(*theEvent).message != theDialog )
  231.                 {
  232.                     MyDoUpdateWindow( (WindowPtr)(*theEvent).message );
  233.                 }
  234.                 else
  235.                 {
  236.                     FnMisc_FrameButton( theDialog, OK_BUTTON );
  237.                 }
  238.                 break;
  239.             case activateEvt:
  240.                 if( (WindowPtr)(*theEvent).message != theDialog )
  241.                 {
  242.                     /*
  243.                     DoActivate_( (WindowPtr)(*theEvent).message,
  244.                                  ((*theEvent).modifiers & activeFlag),
  245.                                  *theEvent );
  246.                     */
  247.                  }
  248.                  break;
  249.         }
  250.         
  251.     return( result );
  252. }
  253.  
  254.  
  255. /**********************************************************************
  256.  
  257.     SampleDialog.r
  258.  
  259. ***********************************************************************/
  260.  
  261. #include <Types.r>
  262. #include <BalloonTypes.r>
  263.  
  264. resource 'CNTL' (500, "Popup", purgeable) {
  265.     {90, 40, 109, 282},
  266.     popupTitleLeftJust,
  267.     visible,
  268.     80,  /* pixel width of title */
  269.     500, /* MENU resource ID */
  270.     popupMenuCDEFProc,
  271.     0,   /* reference value */
  272.     "Database:"
  273. };
  274.  
  275. resource 'MENU' (500, "Popup Items") {
  276.     500,  /* menu ID */
  277.     textMenuProc,
  278.     allEnabled,
  279.     enabled,
  280.     "Popup",
  281.     {
  282.         "Yellow Pages", noIcon, nokey, noMark, plain,
  283.         "White Pages", noIcon, nokey, noMark, plain,
  284.         "Personal Database", noIcon, nokey, noMark, plain
  285.     }
  286. };
  287.  
  288. resource 'DLOG' (500, "Sample Dialog", purgeable) {
  289.     {46, 10, 195, 460},
  290.     movableDBoxProc,
  291.     invisible,
  292.     noGoAway,
  293.     0x0,
  294.     500,
  295.     "Sample Dialog"
  296. };
  297.  
  298. resource 'DITL' (500, "Sample Dialog", purgeable) {
  299.     {    /* array DITLarray: 11 elements */
  300.         /* [1] */
  301.         {119, 382, 139, 440},
  302.         Button {
  303.             enabled,
  304.             "OK"
  305.         },
  306.         /* [2] */
  307.         {119, 311, 139, 369},
  308.         Button {
  309.             enabled,
  310.             "Cancel"
  311.         },
  312.         /* [3] */
  313.         {20, 30, 36, 86},
  314.         StaticText {
  315.             disabled,
  316.             "Name"
  317.         },
  318.         /* [4] */
  319.         {50, 30, 66, 86},
  320.         StaticText {
  321.             disabled,
  322.             "Phone"
  323.         },
  324.         /* [5] */
  325.         {20, 90, 36, 288},
  326.         EditText {
  327.             enabled,
  328.             ""
  329.         },
  330.         /* [6] */
  331.         {50, 90, 66, 288},
  332.         EditText {
  333.             enabled,
  334.             ""
  335.         },
  336.         /* [7] */
  337.         {20, 340, 38, 446},
  338.         RadioButton {
  339.             enabled,
  340.             "Male"
  341.         },
  342.         /* [8] */
  343.         {40, 340, 58, 446},
  344.         RadioButton {
  345.             enabled,
  346.             "Female"
  347.         },
  348.         /* [9] */
  349.         {60, 350, 76, 425},
  350.         StaticText {
  351.             disabled,
  352.             "_______"
  353.         },
  354.         /* [10] */
  355.         {80, 340, 98, 446},
  356.         CheckBox {
  357.             enabled,
  358.             "Married"
  359.         },
  360.         /* [11] */
  361.         {90, 40, 109, 282},
  362.         Control {
  363.             enabled,
  364.             500
  365.         },
  366.         
  367.         {0, 0, 0, 0},
  368.         HelpItem {
  369.           disabled,
  370.           HMScanhdlg
  371.           {500}
  372.         }
  373.     }
  374. };
  375.  
  376.  
  377. /**********************************************************************
  378.  
  379.     SampleDialogBalloons.r
  380.  
  381. ***********************************************************************/
  382.  
  383. #include <Types.r>
  384. #include <BalloonTypes.r>
  385.  
  386. resource 'hdlg' (500, "Sample Dialog Balloons", purgeable){
  387.   /* Header */
  388.   HelpMgrVersion,
  389.   0,                  /* start help with first item in DITL */
  390.   hmDefaultOptions,   /* hmDefaultOptions or hmSaveBitsNoWindow */
  391.   0,                  /* balloon definition */
  392.   5,                  /* variation code or position code, reference
  393.                          IM: More Macintosh Toolbox p3-10 */
  394.   
  395.   /* Missing Component */
  396.   HMSkipItem {
  397.   },
  398.   
  399.   /* Help */
  400.   {
  401.     /* [1] */
  402.     HMStringREsItem { /* store help messages in STR# 500 */
  403.     { 10, 10 },       /* default tip location is { 0, 0 } */
  404.     { 0, 0, 0, 0 },   /* default alternate rectangle */
  405.     500, 1,           /* OK button */
  406.     0, 0,             /* never dimmed */
  407.     0, 0,             /* never checked */
  408.     0, 0              /* never marked */
  409.     },
  410.     
  411.     /* [2] */
  412.     HMStringREsItem {
  413.     { 10, 10 },
  414.     { 0, 0, 0, 0 },
  415.     500, 2,           /* Cancel button */
  416.     0, 0,
  417.     0, 0,
  418.     0, 0
  419.     },
  420.     
  421.     /* [3] */
  422.     HMSkipItem {      /* Name text */
  423.     },
  424.  
  425.     /* [4] */
  426.     HMSkipItem {      /* Phone text */
  427.     },
  428.  
  429.     /* [5] */
  430.     HMStringREsItem {
  431.     { 10, 10 },
  432.     { 0, 0, 0, 0 },
  433.     500, 3,           /* Name field */
  434.     0, 0,
  435.     0, 0,
  436.     0, 0
  437.     },
  438.     
  439.     /* [6] */
  440.     HMStringREsItem {
  441.     { 10, 10 },
  442.     { 0, 0, 0, 0 },
  443.     500, 4,           /* Phone text */
  444.     0, 0,
  445.     0, 0,
  446.     0, 0
  447.     },
  448.  
  449.     /* [7] */
  450.     HMStringREsItem {
  451.     { 5, 5 },
  452.     { 0, 0, 0, 0 },
  453.     500, 5,           /* Male button */
  454.     0, 0,
  455.     500, 6,           /* checked */
  456.     0, 0
  457.     },
  458.  
  459.     /* [8] */
  460.     HMStringREsItem {
  461.     { 3, 3 },
  462.     { 0, 0, 0, 0 },
  463.     500, 7,           /* Female button */
  464.     0, 0,
  465.     500, 8,           /* checked */
  466.     0, 0
  467.     },
  468.  
  469.     /* [9] */
  470.     HMSkipItem {      /* Phone text */
  471.     },
  472.  
  473.     /* [10] */
  474.     HMStringREsItem {
  475.     { 10, 1 },
  476.     { 0, 0, 0, 0 },
  477.     500, 9,            /* Married box */
  478.     0, 0,
  479.     500, 10,           /* checked */
  480.     0, 0
  481.     },
  482.  
  483.     /* [11] */
  484.     HMStringREsItem {
  485.     { 10, 10 },
  486.     { 0, 0, 0, 0 },
  487.     0, 0,
  488.     0, 0,
  489.     500, 11,          /* Popup */
  490.     500, 12           /* Popup */
  491.     },
  492.   }
  493. };
  494.  
  495. resource 'STR#' (500, "Sample Dialog Help Strings") {
  496.   {
  497.   /* [1] */
  498.   "To dismiss dialog and save changes, click this button.";
  499.   /* [2] */
  500.   "To dismiss dialog without saving changes, click this button.";
  501.   /* [3] */
  502.   "Enter persons name you wish to add to database.";
  503.   /* [4] */
  504.   "Enter persons phone number you wish to add "
  505.   "to the database.";
  506.   /* [5] */
  507.   "Click this radio button to identify person as male.";
  508.   /* [6] */
  509.   "Identifies person as male.";
  510.   /* [7] */
  511.   "Click this radio button to identify person as female.";
  512.   /* [8] */
  513.   "Identifies person as female.";
  514.   /* [9] */
  515.   "Check this box if person is married.";
  516.   /* [10] */
  517.   "Identifies person as being married.";
  518.   /* [11] */
  519.   "Use pop-up menu to select a database to add person to."; 
  520.   /* [12] */
  521.   "Use pop-up menu to select a database to add person to."; 
  522.   }
  523. };
  524.  
  525. // End of File